<!--
  模块：政策库 - 政策发布 - 首页
-->
<template>
  <div class="policy-publish">
    <AppMainHeader>
      <el-row>
        <el-col :span="22">
          <!-- 查询表单 -->
          <PolictQueryForm @query="handleQuery" :levelOptions="dataOptions" />
        </el-col>
        <el-col :span="2" class="align-right">
          <el-button type="primary" @click="goToAdd">新增动态</el-button>
        </el-col>
      </el-row>
    </AppMainHeader>

    <AppMainContent>
      <!-- 分页表格 -->
      <PolicyTable :childrenList="fatherList" :childrenForm="formParams" />
      <!-- 分页信息 -->
      <Pagination
        v-show="total > 0"
        :total="total"
        :current.sync="formParams.currPage"
        :size.sync="formParams.pageSize"
        @pagination="getListPolicyInfo"
      />
      <div style="text-align:center;margin-top:30px;color:rgb(121, 135, 156)">
        版权所有©2020海门经济技术开发区管理委员会
      </div>
    </AppMainContent>
    <router-view></router-view>
  </div>
</template>

<script>
//引入头部查询子组件
import PolictQueryForm from '../components/PolicyQueryForm/index'

//引入表格子组件
import PolicyTable from '../components/PolicyTable/index'

//引入下拉框信息
import { policyLevelInfo, listPolicyPageInfo } from '@/api/policy/index'

let pageParams = { currPage: 1, pageSize: 12 }
export default {
  name: 'PolicyPublish',
  components: { PolictQueryForm, PolicyTable },
  data() {
    return {
      // 总的数据条数
      total: 0,
      //*等级下拉选项数据
      dataOptions: [],
      listInfo: [],
      formParams: { ...pageParams },
      fatherList: [],
      likeSelect: {},
    }
  },
  created() {
    this.getLevelOptions()
    this.getListPolicyInfo()
  },
  methods: {
    //* 获取级别下拉框信息
    getLevelOptions() {
      policyLevelInfo()
        .then((response) => {
          if (response.code === 200) {
            this.dataOptions = response.data
          }
        })
        .catch(function(error) {
          this.$message.error('系统错误')
        })
    },

    //* 获取政策列表信息
    getListPolicyInfo() {
      listPolicyPageInfo(this.formParams)
        .then((response) => {
          if (response.code === 200) {
            this.total = response.page.total
            this.fatherList = response.data
          }
        })
        .catch(function(error) {
          alert('系统错误')
        })
    },

    handleQuery(formParams) {
      this.likeSelect = formParams
      this.formParams = { ...formParams, ...pageParams }
      this.getListPolicyInfo()
    },
    goToAdd() {
      this.$router.push('/policy/policyPublishAdd')
    },
  },
}
</script>

<style scoped>
</style>
